// components/swipper/index.ts
import { preparePullLiveStream } from '../../api/index'
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    swipperItems: {
      type: Array,
      value: [
        {
          pic: "https://pic0.iqiyipic.com/image/20220907/24/81/a_100473764_m_601_m3_480_270.webp",
          code: 1
        },
        {
          pic: "https://pic6.iqiyipic.com/image/20220802/4e/43/a_100432060_m_601_m5_480_270.webp",
          code: 2
        },
        {
          pic: "https://pic5.iqiyipic.com/image/20210826/ab/ba/a_100420992_m_601_m7_480_270.webp",
          code: 3
        },
      ]
    },
    swiperConfig: {
      type: Object,
      value: {
        indicatorDots: true,
        autoplay: true,
        interval: 3000,
        duration: 500,
        circular: true
      }
    },
    isShowPlay: {
      type: Boolean,
      value: true
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },
  pageLifetimes: {
    show: function () {
      // console.log('this.data.swipperItems', this.data.swipperItems);
    }
  },
  observers: {
    swipperItems(val) {
      // console.log('this.data.swipperItems', this.data.swipperItems);
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    onTap(event) {
      app.globalData.currentPlayVideoID = event.currentTarget.dataset.code;
      app.globalData.currentPlayElv = event.currentTarget.dataset.elvname;
      app.globalData.CameraOrigin = event.currentTarget.dataset.cameraorigin;
      app.globalData.currentEnterPriseID = event.currentTarget.dataset.enterpriseid;
      this.triggerEvent('swiperTap')
    },
    onChange(e) {
      let pages = getCurrentPages()
      let page = pages[pages.length - 1];
      if(page == null) return
      if (!['pages/home/index','pages/enterprise/index'].includes(page.route)) return
      let { current } = e.detail
      let value = this.data.swipperItems[current]
      if (value.code && value.elvName && app.globalData.token) {
        preparePullLiveStream({
          CamID: value.code,
          ELVName: value.elvName
        })
      }
    }
  }

})
export { }